#include <stdio.h>
#include <string.h> 
#include <stdlib.h>

#define MAX_LEN 10000


int* Build_nextForKMP(const char* template, int next[]){
    // 遍历 template 串
    // i 表示当前位置
    // j 表示前缀位置
    int i = 0;
    int j = -1;
    int sz = strlen(template);
    next[0] = -1;
    while(i < sz){
	if(j < 0 || template[i] == template[j]){
	    next[i + 1] = j + 1; 
	    ++i;++j;
	}
	else{
	    j = next[j];
	}	
    }

    return next;
}

int KMP_match(const char* major, const char* template, size_t pos){
    
    int i = pos; int j = 0;
    size_t sz_major = strlen(major);
    size_t sz_template = strlen(template); 
    int next[sz_template + 5]; 
    Build_nextForKMP(template, next);
    while(i < sz_major && j < sz_template){
	if(major[i] == template[j]){
	    ++j;
	    ++i;
	}
	else{
	    if(j == 0) ++i;	
	    else j = next[j];
	}
    }

    return j == sz_template ? i - sz_template : -1; 
}

void Build_next(const char *t, int *next){
    assert(t);
    // 遍历 模版串t
    int i = 0;
    // 遍历 前缀
    int j = -1;
    int sz = strlen(t);
    next[0] = -1;
    while(i < sz && j < sz){
	if(j < 0 || t[i] == t[j]){
	    next[++i] = ++j;
	}
	else{
	    j = next[j];
	}
    }
}


int KMP_match(const char *s, const char *t, int pos){
    int i = pos; int j = 0;
    int sz_s = (int)strlen(s);
    int sz_t = (int)strlen(t);
    
    int *next = (int*)malloc((sizeof(int)+5)*sz_t); 
    Build_next(t, next);
    while(i < sz_s && j < sz_t){
	if(j < 0 || s[i] == t[j]){++i,j++;}
	else{
	    j = next[j];
	}
    }
}



int main(){
    char* major_str = (char*)malloc(MAX_LEN);
   //fgets(major_str, 100, stdin); 
    scanf("%s", major_str);    
    char* sub_str = (char*)malloc(MAX_LEN);
    //fgets(sub_str, 100, stdin);
    scanf("%s", sub_str);    
    printf("%d\n", KMP_match(major_str, sub_str, 0) );   

    return 0; 
}
